/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.univalle.persistencia;

import co.edu.univalle.modelo.Proveedores;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author valentina
 */
@Stateless
public class ProveedoresDAO implements IProveedoresDAO {

    @PersistenceContext
    private EntityManager entityManager;

    
    @Override
    public void registrar(Proveedores proveedor) {
         try{
         entityManager.persist(proveedor);
     }
     catch (RuntimeException e){
     throw e;
    }
    }

    @Override
    public void modificar(Proveedores proveedor) {
         try{
         entityManager.merge(proveedor);
     }
     catch (RuntimeException e){
     throw e;
    }
    }

    @Override
    public void eliminar(Proveedores proveedor) {
         try{
         entityManager.remove(proveedor);
     }
     catch (RuntimeException e){
     throw e;
    }
    }

    @Override
    public List<Proveedores> consultar() {
        try{
                String jpql = "SELECT c FROM Proveedores c";
                Query query = entityManager.createQuery(jpql);
                return query.getResultList();
         
     }
     catch (RuntimeException e){
     throw e;
}
    }

    @Override
    public Proveedores consultarPorIdProveedor(Integer idproveedor) {
       try{
                    return entityManager.find(Proveedores.class, idproveedor);
     }
                
     catch (RuntimeException e){
     throw e;
       
        }
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
}
